package fr.fitec.qcmPlus.actionForms;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import javax.servlet.http.*;

public final class AuthentificationForm extends ActionForm {

	private static final long serialVersionUID = 1L;
	private String login = null;
    private String password= null;

    public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}



    public void reset(ActionMapping mapping, HttpServletRequest request) {
        this.login = null; this.password = null ;
    }


    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();

        if ((this.login == null) || (this.login.length() < 4))
        	errors.add("login", new ActionMessage("authentification.form.login.noncorrecte"));
        if ((password == null) || (password.length() < 4))
        	errors.add("password", new ActionMessage("authentification.form.password.noncorrecte"));
        return errors;
    }
}
